/**
 * Created by Administrator on 15-7-1.
 */
//默认回复
var DefaultReply = RichBase.extend({
	statics : {
		type : "DEFAULT"
	},
	EVENTS : {
		"click" : {
			"#submitBtn_defaultReply" : "onSubmit"
		}
	},
	getHash : function(){ return $("#hashHidInp").val()},
	init : function(){
		this.submitBtn = $("#submitBtn_defaultReply");
		this.replyTextarea = $("#reply_default_textarea");
	},
	pullData : function(){
		var that = this;
		var hash = this.getHash();
		if(!hash) return false;
		var type = this.statics.type;
		XHR.getReply(hash,type,{
			loading : function(){},
			removeLoading : function(){},
			success : function(res){
				var type = res.msg_type;
				var lists = res.lists || [];
				var val = lists[0] || {};
				val = val.digest || "";
				that.replyTextarea.val(val);
			},
			fail : function(){},
			timeout : function(){},
			error : function(){}
		})
	},
	onSubmit : function(that,e){
		var val = that.replyTextarea.val();
		var hash = that.getHash();
		if(!hash || !val) return false;
		var submitBtn = that.submitBtn;
		if(submitBtn.hasClass("loading")) return false;
		XHR.submit.DEFAULT(hash,val,{
			loading : function(){
				submitBtn.text("正在提交...").addClass("loading");
			},
			removeLoading : function(){
				submitBtn.text("提交").removeClass("loading");
			},
			success : function(res){
				PFT_GLOBAL.U.Alert("success",'<p style="width:160px">保存成功</p>')
			},
			fail : function(res){
				var msg = res.msg || "保存失败";
				PFT_GLOBAL.U.Alert("fail",'<p style="width:200px">'+msg+'</p>');
			},
			timeout : function(res){
				PFT_GLOBAL.U.Alert("fail",'<p style="width:160px;">请求超时</p>');
			},
			serverError : function(res){
				PFT_GLOBAL.U.Alert("fail",'<p style="width:160px;">请求出错</p>');
			}
		})
	}
})